<script>

    
    var page_selecteHosAndPerson = (function($, page_selecteHosAndPerson) {
        function setSerachInfo(id,value){
            var info = StoreCache.getCache("searchInfo");
            if(!info){
                info={};
            }
            info[id]=value;
            StoreCache.setCache("searchInfo",info);
        }
        //setSerachInfo 方法写在js/common.js中

        function initData(){
            var Info =  StoreCache.getCache("searchInfo");
            if(Info){
                if(Info.hosName){
                    $("#hosTite")[0].innerHTML=Info.hosName;
                    $("#hosTite").attr("name",Info.hosCode);
                    $("#hosTite").addClass("blackFont");
                }
                if(Info.userName){
                    $("#cardNum")[0].innerHTML=Info.userName;
                    $("#cardNum").addClass("blackFont");
                }
                if(Info.beginTime){
                    $('#beginTime').val(Info.beginTime).addClass("blackFont");
                }
                if(Info.endTime){
                    $('#endTime').val(Info.endTime).addClass("blackFont");
                }
            }
            $(".search").click(page_selecteHosAndPerson.search);
        }

        function search(){
            var obj =  StoreCache.getCache("searchInfo");
            if(!obj || !obj.hosCode){
                $.QuickAlert.alertFail({
                    content :"请选择医院进行查找!"
                });
            }else if(!obj.userName){
                $.QuickAlert.alertFail({
                    content :"请选择就诊人!"
                });
            }else{
                var userInfo = JSON.parse(obj.userInfo)
                page_selecteHosAndPerson.setSerachInfo("patientCardId",userInfo.sfzh);
                switch(titleType){
                    case "findBills":
                        $.pageSwitch.goToUrl("onlinePay","myBills");
                        break;
                    case "searchHosPay":
                        $.pageSwitch.goToUrl("treatmentPay","zyjrResult");
                        break;
                    case "searchHosRecords":
                        $.pageSwitch.goToUrl("hospitalRecords","hospitalListing");
                        break;
                    case "elePaper":
                        $.pageSwitch.goToUrl("electPrescription","presListing");
                        break;
                    case "searchReport":
                        $.pageSwitch.goToUrl("searchReport","reportList");
                        break;

                }
            }
        }
        function changeTime(id) {
            var myDate = new Date();
            var nowYear = myDate.getFullYear();
            var options = JSON.parse('{"type":"date","beginYear":1900,"endYear":2018}');
            var picker = new mui.DtPicker(options);
            picker.show(function (selectItems) {
                var value = selectItems.y.text + '-' + selectItems.m.text + '-' + selectItems.d.text;
                $('#' + id).val(value).addClass("blackFont");
                page_selecteHosAndPerson.setSerachInfo(id,value);
            })
        }

        var cfg_def = {
            initData: initData,
            setSerachInfo: setSerachInfo,
            search: search,
            changeTime: changeTime,
        }

        page_selecteHosAndPerson.init = function(cfg){
            $.extend(page_selecteHosAndPerson, cfg_def, cfg);
            page_selecteHosAndPerson.initData();
            $.pageSwitch.clickToUrl(".choose-box","common");
            $("#beginTime").click(function () {
                page_selecteHosAndPerson.changeTime('beginTime')
            })
            $("#endTime").click(function () {
                page_selecteHosAndPerson.changeTime('endTime')
            })
        }

        return page_selecteHosAndPerson;
    })(jQuery, {});
    


</script>